#!/bin/sh
#desc:Sound
CFGFILE="/etc/opendomo/sound.conf"
PIDFILE="/var/run/sound.pid"
AMIXER="/usr/bin/amixer"

case "$1" in
  start)
	# Loading standard sound modules
	modprobe snd_hda_intel
	echo -n "Starting sound system ..."
	if test -f "$PIDFILE"; then
		exit 2
	else
		if test -f $CFGFILE; then
			alsactl -f $CFGFILE restore 2>/dev/null	
			echo "1" > $PIDFILE
			chown admin $PIDFILE 2>/dev/null
			$AMIXER set -c 0 Master 100% unmute 2>/dev/null >/dev/null
			/usr/bin/aplay -q /usr/share/sounds/click.wav &
			exit 0
		else
			exit 1
		fi
	fi
	;;

  status)
	if test -f "$PIDFILE"; then
  		echo "The service is running"
  		exit 0
	else
  		echo "Service not started"
  		exit 1
	fi
	;;

  stop)
	rm $PIDFILE 2>/dev/null
	if test -f $CFGFILE; then
		alsactl -f $CFGFILE store 2>/dev/null
		$AMIXER set -c 0 Master 100% mute  2>/dev/null >/dev/null
		exit 0
	else
		exit 2
	fi
	;;

  reload)
	echo -n "Reloading sound system ..."
	;;

  restart)
	echo -n "Restarting sound system ..."
	$0 stop
	$0 start
	;;
  *)
	echo $"Usage: $0 {start|stop|restart|reload|status}"
	exit 1
esac
